﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace L10
{
    public partial class FrmMain : Form
    {
        private int x, y;//鼠标当前坐标
        private int timerTickCount = 0;//计时器的次数


        public FrmMain()
        {
            InitializeComponent();
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat(
                "窗体大小（像素）：{0},{1}",
                this.Width.ToString(), 
                this.Height.ToString()
                );
            sb.AppendLine();
            sb.AppendFormat(
                "工作区域大小（像素）：{0},{1}",
                this.ClientRectangle .Width .ToString (),
                this.ClientRectangle.Height .ToString()
                );
            MessageBox.Show(sb.ToString(), "信息提示");
            //初始化计时器Timer1
            this.toolStripStatusLabel1.Text  = "计时次数：" + timerTickCount.ToString();
            this.timer1.Interval = 1000;//间隔一秒
            this.timer1.Start();

        }

        private void FrmMain_KeyDown(object sender, KeyEventArgs e)
        {
            Debug.WriteLine(e.KeyCode.ToString ());
            //按Esc键关闭窗口
            if(e.KeyCode ==Keys.Escape )
            {
                this.Close();
            }
        }

        private void FrmMain_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button ==MouseButtons.Left )
            {
                MessageBox.Show("单击鼠标左键", "提示");
            }else if(e.Button ==MouseButtons.Right )
            {
                MessageBox.Show("单击鼠标右键", "提示");
            }else if(e.Button ==MouseButtons.Middle )
            {
                MessageBox.Show("单击鼠标中键", "提示");
            }
        }

        private void FrmMain_MouseMove(object sender, MouseEventArgs e)
        {
            this.x = e.X;
            this.y = e.Y;
            this.Invalidate();
        }

        private void FrmMain_Paint(object sender, PaintEventArgs e)
        {
            //图形类
            Graphics g = e.Graphics;

            //绘制鼠标坐标信息--文字
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("鼠标当前坐标：{0}，{1}", x.ToString(), y.ToString());
            g.DrawString(sb.ToString (),
                new Font ("微软雅黑",20f),
                new SolidBrush (Color .Crimson ),
                this.ClientRectangle.Width / 2+50, this.ClientRectangle.Height / 2-50
                );

            //绘制分割线
            Pen pen = new Pen(Color.Black, 2.0f);
            g.DrawLine(pen,
                this.ClientRectangle.Width / 2, 0,
                this.ClientRectangle.Width / 2, this.ClientRectangle.Height);
            g.DrawLine(pen,
                0, this.ClientRectangle.Height  / 2,
                this.ClientRectangle.Width , this.ClientRectangle.Height/2);

            //绘制图形
            pen.Color = Color.Blue;
            g.DrawRectangle(pen, 2, 2, 300, 240);
            g.FillRectangle(new SolidBrush(Color.LightBlue), 15, 15, 274, 214);
            pen.Color = Color.DeepPink;
            g.DrawBezier(pen, 
                new Point(100, 2),
                new Point(10, 10), 
                new Point(100, 200), 
                new Point(120, 100));

            //绘制文字
            g.DrawString("游戏开始",
                new Font("微软雅黑", 32),
                new SolidBrush(Color.OrangeRed),
                new Point(400, 40));

            //绘制图片
            Bitmap bm = new Bitmap(Application.StartupPath + "\\c.png");
            g.DrawImage(bm, new Rectangle(2, 290, 360, 240));

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            timerTickCount++;
            this.toolStripStatusLabel1.Text = "计时次数：" + timerTickCount.ToString();
        }
    }
}
